package org.celery.modules.ticket.enums;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum payStatusEnum {
    /**
     * 未付款
     */
    UNPAID("未付款",  1),
    PAID("已付款",  2),
    FULL_REFUND("全额退款",  4),
    PAYMENT_COMPLETION("回款完成",  6),
    EXTERNAL_PAYMENT_ORDER_NOT_CREATED("未创建外部支付单",  7),
    CANCEL_BEFORE_PAYMENT("付款前取消",  8),
    PAYMENT_IN_PROGRESS("正在支付中",  9),
    TO_BE_RECEIVED("待到账",  12),
    ;
    private final String name;
    private final int value;

    public static String getName(int value) {
        if (value == 1) {
            return UNPAID.getName();
        } else if (value == 2) {
            return PAID.getName();
        } else if (value == 4) {
            return FULL_REFUND.getName();
        } else if (value == 6) {
            return PAYMENT_COMPLETION.getName();
        } else if (value == 7) {
            return EXTERNAL_PAYMENT_ORDER_NOT_CREATED.getName();
        } else if (value == 8) {
            return CANCEL_BEFORE_PAYMENT.getName();
        } else if (value == 9) {
            return PAYMENT_IN_PROGRESS.getName();
        } else if (value == 12) {
            return TO_BE_RECEIVED.getName();
        }
        return "";
    }

    public JSONObject toJSON() {
        JSONObject jo = new JSONObject();
        jo.put("name", name);
        jo.put("value", value);
        return jo;
    }

    public static List<Map<String, Object>> toList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (payStatusEnum item : payStatusEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("name", item.getName());
            map.put("value", item.getValue());
            list.add(map);
        }
        return list;
    }
}
